<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ page import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<SCRIPT src="<%=request.getContextPath()%>/conf_files/js/HeadqInvenTrace.js?v=12.31" type=text/javascript></SCRIPT>
<script>
var baseurl = "<%=request.getContextPath()%>";
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	var params= $.serializeObject($('#preGenReportForm'));
	
	$('#dataGrid').treegrid({
		url : 'headqInventoryFlowJSONAction!getInventoryChangeDetails',
		idField: 'id',
		fit: true,
		queryParams: params,
		treeField : 'name',
		onBeforeExpand : function(node) {
			$("#parentId").val( node.parentId);
		    $("#yearId").val(node.yearId);
			$("#quarterId").val(node.quarterId);
			$("#brandId").val(node.brandId);
			$("#categoryLevelId").val(node.categoryLevelId);
			$("#categoryId").val(node.categoryId);
			$("#pbId").val(node.pbId);
			var params = $('#preGenReportForm').serialize();
			$('#dataGrid').treegrid('options').url = 'headqInventoryFlowJSONAction!getInventoryChangeDetails?' + params;

		},
		frozenColumns: [[
			{field:'name', width:250,title:'<s:property value="uiBean.storeName"/>',
				formatter: function (value, row, index){
					if (row.state == 'open') {
						var str = '';
					    str += $.formatString('<a href="#" onclick="traceInventory(\'{0}\',\'\',\'{1}\');">{2}</a>', row.pbId,row.barcode, row.name);
					    return str;
					} else 
						return row.name;
				}}
	    ]],
		columns : [[
						
					{field:'beforeAmount', width:70,title:'上期-数量',
							styler: function(value, row, index) {					        
						          return 'background-color: #FFD700;'; 					        
						      } },
					{field:'beforeAmountMoney', width:70,title:'上期-金额',formatter: function (value, row, index){
						return (row.beforeAmountMoney).toFixed(2);
					},
					styler: function(value, row, index) {					        
				          return 'background-color: #FFD700;'; 					        
				      } },
					
					{field:'periodPurchaseNums', width:70,title:'A采购数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ffe6e6;'; 					        
					      } },
					{field:'periodPurchaseMoneys', width:80,title:'A采购金额',
						formatter: function (value, row, index){
							return (row.periodPurchaseMoneys).toFixed(2);
						}
					},{field:'periodSaleReturnNums', width:70,title:'A销售退货数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ffe6e6;'; 					        
					      } },
					{field:'periodSaleReturnMoneys', width:80,title:'A销售退货金额',
						formatter: function (value, row, index){
							return (row.periodSaleReturnMoneys).toFixed(2);
						}
					},{field:'periodOverflowNums', width:70,title:'A报溢数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ffe6e6;'; 					        
					      } },
					{field:'periodOverflowMoneys', width:80,title:'A报溢金额',
						formatter: function (value, row, index){
							return (row.periodOverflowMoneys).toFixed(2);
						}
					},{field:'periodReceiveNums', width:70,title:'A获赠数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ffe6e6;'; 					        
					      } },
					{field:'periodReceiveMoneys', width:80,title:'A获赠金额',
						formatter: function (value, row, index){
							return (row.periodReceiveMoneys).toFixed(2);
						}
					},{field:'periodCallInNums', width:70,title:'A调入数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ffe6e6;'; 					        
					      } },
					{field:'periodCallInMoneys', width:80,title:'A调入金额',
						formatter: function (value, row, index){
							return (row.periodCallInMoneys).toFixed(2);
						}
					},{field:'periodEnterNums', width:70,title:'A合计数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ffe6e6;'; 					        
					      } },
					{field:'periodEnterMoneys', width:80,title:'A合计金额',
						formatter: function (value, row, index){
							return (row.periodEnterMoneys).toFixed(2);
						}
					},{field:'periodSaleNums', width:70,title:'B销售数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ADD8E6;'; 					        
					      } },
					{field:'periodSaleMoneys', width:80,title:'B销售金额',
						formatter: function (value, row, index){
							return (row.periodSaleMoneys).toFixed(2);
						}
					},{field:'periodPurchaseReturnNums', width:70,title:'B采购退货数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ADD8E6;'; 					        
					      } },
					{field:'periodPurchaseReturnMoneys', width:80,title:'B采购退货金额',
						formatter: function (value, row, index){
							return (row.periodPurchaseReturnMoneys).toFixed(2);
						}
					},{field:'periodLossNums', width:70,title:'B报损数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ADD8E6;'; 					        
					      } },
					{field:'periodLossMoneys', width:80,title:'B报损金额',
						formatter: function (value, row, index){
							return (row.periodLossMoneys).toFixed(2);
						}
					},{field:'periodGiftNums', width:70,title:'B赠送数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ADD8E6;'; 					        
					      } },
					{field:'periodGiftMoneys', width:80,title:'B赠送金额',
						formatter: function (value, row, index){
							return (row.periodGiftMoneys).toFixed(2);
						}
					},{field:'periodOutNums', width:70,title:'B调出数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ADD8E6;'; 					        
					      } },
					{field:'periodOutMoneys', width:80,title:'B调出金额',
						formatter: function (value, row, index){
							return (row.periodOutMoneys).toFixed(2);
						}
					},{field:'periodOutBoundNums', width:85,title:'B合计数量',
						styler: function(value, row, index) {					        
					          return 'color: red; background-color: #ADD8E6;'; 					        
					      } },
					{field:'periodOutBoundMoneys', width:85,title:'B合计金额',
						formatter: function (value, row, index){
							return (row.periodOutBoundMoneys).toFixed(2);
						}
					},{field:'totalQuantity', width:90,title:'期末合计数量',
						styler: function(value, row, index) {					        
					          return 'background-color: #FFD700;'; 					        
					      } },
					{field:'totalAmount', width:90,title:'期末 合计金额',
						formatter: function (value, row, index){
							return (row.totalAmount).toFixed(2);
						},
						styler: function(value, row, index) {					        
					          return 'background-color: #FFD700;'; 					        
					      } 
					}
			     ]],
		toolbar : '#toolbar',
	});
});

//刷新
function refresh(){
	$("#parentId").val(0);
	$("#yearId").val(0);
	$("#quarterId").val(0);
	$("#brandId").val(0);
	$("#categoryId").val(0);
	$("#pbId").val(0);
	var params = $('#preGenReportForm').serialize();
	$('#dataGrid').treegrid('options').url = 'headqInventoryFlowJSONAction!getInventoryChangeDetails?' + params;
	$('#dataGrid').treegrid('reload');
}

//返回上一级
function goBack(){	
	window.location.href = "headqInventoryFlowJSPAction!preGetInventoryChange";
}

//下载单据
function downloadChangeInventory(){
	var node = $('#dataGrid').treegrid('getSelected');

	if (node == null){
		$.messager.alert('错误', '请先选中一行再继续操作', 'error');
	} else {
		$.messager.confirm('功能确认', '如果日期选择过长,此功能会下载大量数据，如果在繁忙时间可能会拖垮服务器.你确定继续?', function(r){
			if(r){
			    $("#yearId").val(node.yearId);
				$("#quarterId").val(node.quarterId);
				$("#brandId").val(node.brandId);
				$("#categoryId").val(node.categoryId);
				$("#pbId").val(node.pbId);
		        document.preGenReportForm.action="headqInventoryFlowJSPAction!downloadChangeInventory";
		        document.preGenReportForm.submit();
			}
		});

	}
}

//下载层级报表
function downloadLevelReport(){
	var node = $('#dataGrid').treegrid('getSelected');

	if (node == null){
		$.messager.alert('错误', '请先选中一行再继续操作', 'error');
	} else {
	    $("#yearId").val(node.yearId);
		$("#quarterId").val(node.quarterId);
		$("#brandId").val(node.brandId);
		$("#categoryId").val(node.categoryId);
		$("#pbId").val(node.pbId);
		$("#parentId").val(1);
        document.preGenReportForm.action="headqInventoryFlowJSPAction!downloadLevelReport";
        document.preGenReportForm.submit();
	}
}

</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
	    <div data-options="region:'north',border:false" style="height: fit">
        <s:form id="preGenReportForm" name="preGenReportForm" action="" theme="simple" method="POST">  
        	<s:hidden name="formBean.startDate" id="startDate" />
			<s:hidden name="formBean.endDate" id="endDate" />
            <input type="hidden" name="formBean.yearId" id="yearId" value="0"/>
            <input type="hidden" name="formBean.quarterId" id="quarterId" value="0"/>
            <input type="hidden" name="formBean.brandId" id="brandId" value="0"/>
            <input type="hidden" name="formBean.categoryLevel1Id" id="categoryLevelId" value="0"/>
            <input type="hidden" name="formBean.categoryId" id="categoryId" value="0"/>
            <input type="hidden" name="formBean.pbId" id="pbId" value="0"/>
            <s:hidden name="formBean.rptTypeId" id="rptTypeId"/>
            <s:hidden name="formBean.storeId" id="storeId"/>
            <s:hidden name="formBean.storeIds" id="storeIds"/>
            <s:hidden name="formBean.belongTo" id="belongTo"/>
            <s:hidden name="formBean.parentId" id="parentId" />
        </s:form>
        </div>
		<div data-options="region:'center',border:false">
			    <table id="dataGrid" style="width:1890px;height:fit">			       
		        </table>
		        <div id="toolbar" style="display: none;">
		        	<a onclick="goBack();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-back'">返回上页</a>
		             <a onclick="refresh();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">刷新库存</a>
		             <a onclick="downloadChangeInventory();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">下载库存</a>	
		             <a onclick="downloadLevelReport();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">下载层级报表</a>		           
	             </div>
		</div>
	</div>					  
</body>
</html>